package com.lagou.edu.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.lagou.edu.service.SentinelHandlers;
import com.lagou.edu.service.impl.CodeServiceImpl;
import com.lagou.edu.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeServiceImpl codeService;

    @GetMapping("/create/{email}")
    @SentinelResource(value = "generateCode",blockHandlerClass = SentinelHandlers.class,
            blockHandler = "generateCodeHandle",fallbackClass = SentinelHandlers.class,fallback = "generateCodeFallBack")
    public Result generateCode(@PathVariable String email) {
        return codeService.generateCode(email);
    }

    @GetMapping("/validate/{email}/{code}")
    @SentinelResource(value = "validateCode",blockHandlerClass = SentinelHandlers.class,
            blockHandler = "validateCodeHandle",fallbackClass = SentinelHandlers.class,fallback = "validateCodeFallBack")
    public Integer validateCode(@PathVariable String email,@PathVariable String code) {
        return codeService.validateCode(email,code);
    }



}
